package com.kamistoat.meimeimall.meimeimallcart.vo;

import com.kamistoat.meimeimall.common.To.orderTo.OrderItemTo;

import java.math.BigDecimal;
import java.util.List;

// 整个购物车，第一层Map
public class CartVo {
    List<OrderItemTo> orderItemTos;
    private Integer totalCount;  // 商品总数
    private Integer typeCount;  // 商品种类数
    private BigDecimal amountPrice;  // 商品总价
    private BigDecimal reduce = new BigDecimal("0");  // 减免价格

    public List<OrderItemTo> getOrderItemTos() {
        return orderItemTos;
    }

    public void setOrderItemTos(List<OrderItemTo> orderItemTos) {
        this.orderItemTos = orderItemTos;
    }

    // 商品总数
    public Integer getTotalCount() {
        int count = 0;
        if (this.orderItemTos != null && this.orderItemTos.size() > 0) {
            for (OrderItemTo orderItemTo : this.orderItemTos) {
                count = count + orderItemTo.getCount();
            }
        }
        return count;
    }

    // 商品总种类数
    public Integer getTypeCount() {
        int count = 0;
        if (this.orderItemTos != null && this.orderItemTos.size() > 0) {
            for (OrderItemTo orderItemTo : this.orderItemTos) {
                count = count + 1;
            }
        }
        return count;
    }

    // 商品总价格
    public BigDecimal getAmountPrice() {
        BigDecimal amount = new BigDecimal("0");
        // 计算所有商品的总价格
        if (this.orderItemTos != null && this.orderItemTos.size() > 0) {
            for (OrderItemTo orderItemTo : this.orderItemTos) {
                if (orderItemTo.getCheck()) {
                    BigDecimal totalPrice = orderItemTo.getTotalPrice();
                    amount = amount.add(totalPrice);
                }
            }
        }
        // 减去优惠信息
        amount = amount.subtract(this.reduce);
        return amount;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
